﻿using System;
using System.Collections.ObjectModel;
using System.Windows.Input;
using Micua.iChat.Common;
using Micua.iChat.Models;
using Windows.ApplicationModel;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Data;

namespace Micua.iChat.ViewModels
{
    public class MainViewModel : ViewModelBase
    {
        public double TitleWidth { get; set; }
        public User CurrentUser { get; set; }

        public ObservableCollection<Message> RecentMessages { get; set; }
        public ObservableCollection<MenuItem> FunctionMenus { get; set; }
        public CollectionViewSource Friends { get; set; }

        public MainViewModel()
        {

            Friends = new CollectionViewSource();

            TitleWidth = Window.Current.Bounds.Width - 40;
            if (DesignMode.DesignModeEnabled)
            {
                TitleWidth = 360;
            }
            if (DesignMode.DesignModeEnabled)
            {
                // 如果是设计器
                CurrentUser = new User
                {
                    //Id = 10001,
                    Username = "CZ0924",
                    Signature = "屌丝要逆袭"
                };
                #region RecentMessages
                RecentMessages = new ObservableCollection<Message>
            {
                new Message { FromId = 10001, ToId = 10000, FromUsername = "张大炮", ToUsername = "张小平", Content = "约吗？", IsRead = false, SendTime = DateTime.Now },
                new Message { FromId = 10001, ToId = 10000, FromUsername = "张大炮", ToUsername = "张小平", Content = "约吗？", IsRead = false, SendTime = DateTime.Now.AddDays(-1) },
                new Message { FromId = 10001, ToId = 10000, FromUsername = "张大炮", ToUsername = "张小平", Content = "约吗？", IsRead = false, SendTime = DateTime.Now.AddDays(-1) },
                new Message { FromId = 10001, ToId = 10000, FromUsername = "张大炮", ToUsername = "张小平", Content = "约吗？", IsRead = false, SendTime = DateTime.Now.AddDays(-1) },
                new Message { FromId = 10001, ToId = 10000, FromUsername = "张大炮", ToUsername = "张小平", Content = "约吗？", IsRead = false, SendTime = DateTime.Now.AddDays(-1) },
                new Message { FromId = 10001, ToId = 10000, FromUsername = "张大炮", ToUsername = "张小平", Content = "约吗？", IsRead = false, SendTime = DateTime.Now.AddDays(-1) },
                new Message { FromId = 10001, ToId = 10000, FromUsername = "张大炮", ToUsername = "张小平", Content = "约吗？", IsRead = false, SendTime = DateTime.Now.AddMonths(-1) },
                new Message { FromId = 10001, ToId = 10000, FromUsername = "张大炮", ToUsername = "张小平", Content = "约吗？", IsRead = false, SendTime = DateTime.Now.AddDays(-1) },
                new Message { FromId = 10001, ToId = 10000, FromUsername = "张大炮", ToUsername = "张小平", Content = "约吗？", IsRead = false, SendTime = DateTime.Now.AddSeconds(-1) },
                new Message { FromId = 10001, ToId = 10000, FromUsername = "张大炮", ToUsername = "张小平", Content = "约吗？", IsRead = false, SendTime = DateTime.Now.AddDays(-1) },
                new Message { FromId = 10001, ToId = 10000, FromUsername = "张大炮", ToUsername = "张小平", Content = "约吗？", IsRead = false, SendTime = DateTime.Now.AddDays(-1) },
                new Message { FromId = 10001, ToId = 10000, FromUsername = "张大炮", ToUsername = "张小平", Content = "约吗？", IsRead = false, SendTime = DateTime.Now.AddDays(-1) },
                new Message { FromId = 10001, ToId = 10000, FromUsername = "张大炮", ToUsername = "张小平", Content = "约吗？", IsRead = false, SendTime = DateTime.Now.AddDays(-1) },
                new Message { FromId = 10001, ToId = 10000, FromUsername = "张大炮", ToUsername = "张小平", Content = "约吗？", IsRead = false, SendTime = DateTime.Now.AddDays(-1) },
                new Message { FromId = 10001, ToId = 10000, FromUsername = "张大炮", ToUsername = "张小平", Content = "约吗？", IsRead = false, SendTime = DateTime.Now.AddDays(-1) },
            };
                #endregion

                #region Friends
                var temp = new ObservableCollection<FriendGroup>();
                Friends = new CollectionViewSource();
                Friends.IsSourceGrouped = true;
                Friends.ItemsPath = new PropertyPath("Friends");
                Friends.Source = temp;

                #endregion

                FunctionMenus = new ObservableCollection<MenuItem>
                {
                    new MenuItem{ Id=1, Icon="MapPin", Label="附近的人" },
                    new MenuItem{ Id=1, Icon="Link", Label="数据线" },
                    new MenuItem{ Id=1, Icon="MapPin", Label="扫一扫" },
                    new MenuItem{ Id=1, Icon="Favorite", Label="空间" },
                    new MenuItem{ Id=1, Icon="Globe", Label="官网" },
                    new MenuItem{ Id=1, Icon="Mail", Label="邮箱" },
                    new MenuItem{ Id=1, Icon="Setting", Label="设置" },
                    new MenuItem{ Id=1, Icon="ViewAll", Label="更多" },
                };
            }
        }
    }



    public class MenuItem
    {
        public MenuItem()
        {
            ClickCommand = new Command(p => true, p => { });
        }
        public int Id { get; set; }
        public string Icon { get; set; }
        public string Label { get; set; }
        public ICommand ClickCommand { get; set; }
    }
}
